package com.wisdudu.blank.support.util;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.view.View;

import com.wisdudu.blank.app.App;

import static android.content.Context.TELEPHONY_SERVICE;

/**
 * Created by qyf on 2016/3/12.
 */
public class AppUtil {
    private AppUtil() {
/* cannot be instantiated */
        throw new UnsupportedOperationException("cannot be instantiated");
    }

    /**
     * 获取包信息，包括版本信息等
     */
    public static PackageInfo getPackageInfo(Context context) {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = null;
        try {
            packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return packageInfo;
    }

    public static String getIMEI(){
        return ((TelephonyManager) App.getContext().getSystemService(TELEPHONY_SERVICE)).getDeviceId();

    }

    /**
     * activity 无参数跳转
     */
    public static void jumpActivity(Context context, Class c) {
        Intent intent = new Intent(context, c);
        context.startActivity(intent);
    }

    public static void openApp(Context context, String packageName) {
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
        if (intent != null) {
            context.startActivity(intent);
        }else {
            ToastUtil.INSTANCE.toast("您的手机上没有安装嘟嘟E家！");
        }
    }
    public static void setTranslucent(View view, Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            view.setPadding(0, getStatusBarHeight(context), 0, 0);
        }
    }
    public static int getStatusBarHeight(Context context) {
        // 获得状态栏高度
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        return context.getResources().getDimensionPixelSize(resourceId);
    }
}
